package cn.wit.test;

import org.junit.Test;

public class DemoThread2 {
	public static void main(String[] args) {

		// Thread t1 = new Thread(() -> {
		//
		// while (true) {
		//
		// System.out.println("666");
		// }
		//
		// });
		//
		// t1.start();

		Thread t2 = new Thread(new printString("我正在跑后台任务。。。", 100));

		Thread t3 = new Thread(new printNumber(100D));

		t2.start();
		t3.start();
		
	}

	@Test
	public void test() throws InterruptedException {
		
		Thread t2 = new Thread(new printString("我正在跑后台任务。。。", 100));

		Thread t3 = new Thread(new printNumber(100D));

		t2.start();
		t3.start();
		
		//加入线程
		t2.join();
		t3.join();
	}
}

class printString implements Runnable {

	private String message;

	private int count;

	public printString(String msg, int count) {
		this.message = msg;
		this.count = count;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (count-- > 0) {
			System.out.println(this.message);
		}

	}

}

class printNumber implements Runnable {
	private Double num;

	public printNumber(Double num) {

		this.num = num;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (this.num > 0) {
			System.out.println(this.num);
			this.num = this.num - 1;
		}

	}

}
